Skip to content

fix(control-plane): map AgentID in gRPC session event deserialization#1472

Merged
markturansky merged 2 commits intoambient-code:mainfrom
jsell-rh:jsell/fix/cp-agent-id
Apr 27, 2026
Merged

fix(control-plane): map AgentID in gRPC session event deserialization#1472
markturansky merged 2 commits intoambient-code:mainfrom
jsell-rh:jsell/fix/cp-agent-id

Conversation

@jsell-rh
Copy link
Copy Markdown
Contributor

@jsell-rh jsell-rh commented Apr 27, 2026

Summary

  • protoSessionToSDK() in the control plane informer was missing the AgentID field mapping
  • All sessions received via gRPC watch events had empty AgentID, causing:
    • AGENT_ID="" env var on runner pods
    • assembleInitialPrompt() skipping the agent prompt lookup
    • Agent prompts never included in INITIAL_PROMPT

One-line fix: add AgentID: s.GetAgentId() to the struct literal in informer.go.

Test plan

  • Unit test TestProtoSessionToSDK_AllFieldsMapped covers all 33 session fields including AgentID
  • Test passes with fix: all fields correctly mapped
  • Test fails without fix: AgentID: got , want agent-456
  • Verified on staging (vteam-stage): pod session-3cx0er4tsqemxkbhjiwyvym2hbb-runner had AGENT_ID= (empty) and INITIAL_PROMPT=write a poem (missing agent prompt "you always talk like a caveman")
  • After deploying fix: verify new sessions with agent association have AGENT_ID set and INITIAL_PROMPT includes agent prompt

Reproduction steps

  1. Create an agent with a prompt: acpctl create agent --name cave-man --prompt "you always talk like a caveman"
  2. Create a session tied to that agent with its own prompt: acpctl create session --agent-id <id> --prompt "write a poem"
  3. Check the runner pod env: oc get pod <pod> -n <ns> -o jsonpath='{.spec.containers[0].env}' | jq '.[] | select(.name == "AGENT_ID" or .name == "INITIAL_PROMPT")'
  4. Before fix: AGENT_ID=, INITIAL_PROMPT=write a poem
  5. After fix: AGENT_ID=agent-456, INITIAL_PROMPT=you always talk like a caveman\n\nwrite a poem

Test output

$ go test ./internal/informer/ -run TestProtoSessionToSDK -v
=== RUN   TestProtoSessionToSDK_NilReturnsZero
--- PASS: TestProtoSessionToSDK_NilReturnsZero (0.00s)
=== RUN   TestProtoSessionToSDK_AllFieldsMapped
--- PASS: TestProtoSessionToSDK_AllFieldsMapped (0.00s)
PASS
ok  	.../ambient-control-plane/internal/informer	0.003s

# With fix reverted:
=== RUN   TestProtoSessionToSDK_AllFieldsMapped
    informer_test.go:106: AgentID: got , want agent-456
--- FAIL: TestProtoSessionToSDK_AllFieldsMapped (0.00s)
FAIL

🤖 Generated with Claude Code

The gRPC watch event deserializer was missing the AgentID field mapping,
causing all sessions received via gRPC to have an empty AgentID. This
meant the reconciler set AGENT_ID="" on runner pods and skipped the
agent prompt lookup in assembleInitialPrompt, so agent prompts were
never included in INITIAL_PROMPT.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 27, 2026

Deploy Preview for cheerful-kitten-f556a0 canceled.

Name Link
🔨 Latest commit 8fa6a1c
🔍 Latest deploy log https://app.netlify.com/projects/cheerful-kitten-f556a0/deploys/69efa9bdd75e61000829c6f7

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

Warning

Rate limit exceeded

@jsell-rh has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 43 minutes and 19 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 973a1fdb-1bc3-4208-a696-d0b2dd5680a8

📥 Commits

Reviewing files that changed from the base of the PR and between e10fda7 and 8fa6a1c.

📒 Files selected for processing (1)
  • components/ambient-control-plane/internal/informer/informer_test.go
📝 Walkthrough

Walkthrough

The protoSessionToSDK conversion function is updated to map the AgentId proto field into the SDK's types.Session.AgentID, enriching session resource instances with agent identification data during conversion.

Changes

Cohort / File(s) Summary
Session AgentID Mapping
components/ambient-control-plane/internal/informer/informer.go
Added AgentID field mapping in protoSessionToSDK conversion to include agent identification in SDK session instances.
🚥 Pre-merge checks | ✅ 7 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (7 passed)
Check name Status Explanation
Title check ✅ Passed Title follows Conventional Commits format (fix type, control-plane scope) and accurately describes the main change: adding AgentID field mapping in gRPC session deserialization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Performance And Algorithmic Complexity ✅ Passed Single O(1) field mapping added to protoSessionToSDK function called once per gRPC event with no performance implications.
Security And Secret Handling ✅ Passed PR adds AgentID field mapping in gRPC deserialization. AgentID is a functional string identifier, not a credential or token. No plaintext secrets, hardcoded values, injection vulnerabilities, or unauthorized data exposure introduced.
Kubernetes Resource Safety ✅ Passed PR modifies only gRPC session-to-SDK conversion logic in Go source file, adding AgentID field mapping. No Kubernetes manifests, resource definitions, RBAC, or infrastructure code affected.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jsell-rh jsell-rh marked this pull request as draft April 27, 2026 18:14
@jsell-rh jsell-rh force-pushed the jsell/fix/cp-agent-id branch from 4ae91fa to 449c82d Compare April 27, 2026 18:21
@jsell-rh jsell-rh marked this pull request as ready for review April 27, 2026 18:22
Table-driven test verifies every proto Session field is correctly mapped
to the SDK types.Session struct, including AgentID. Prevents future
field omissions from going undetected.

Includes standalone session test (no agent_id) to verify optional fields
safely deserialize as empty strings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jsell-rh jsell-rh force-pushed the jsell/fix/cp-agent-id branch from 449c82d to 8fa6a1c Compare April 27, 2026 18:23
@jsell-rh
Copy link
Copy Markdown
Contributor Author

@CodeRabbit recheck

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

@jsell-rh Sure, triggering a re-review now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@markturansky markturansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@markturansky markturansky merged commit 9affddf into ambient-code:main Apr 27, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants